<template>
  <a-dropdown v-if="nickname" placement="bottomRight">
    <span class="ant-pro-account-avatar">
      <a-avatar size="small" :src="baseUrl" class="antd-pro-global-header-index-avatar" />
      <span>{{ nickname }}</span>
    </span>
    <template v-slot:overlay>
      <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
        <a-menu-item key="center" @click="handleToCenter">
          <a-icon type="home" />
          首页
        </a-menu-item>
        <a-menu-item key="settings" @click="handleToSettings">
          <a-icon type="setting" />
          个人设置
        </a-menu-item>
        <a-menu-divider />
        <a-menu-item key="logout" @click="handleLogout">
          <a-icon type="logout" />
          退出登录
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
  <span v-else>
    <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
  </span>
</template>

<script>
import { Modal } from 'ant-design-vue'
import { mapGetters } from 'vuex'
import store from '@/store/index'
export default {
  name: 'AvatarDropdown',
  props: {
    currentUser: {
      type: Object,
      default: () => null
    },
    menu: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      baseUrl: ''
    }
  },
  created () {
    if (this.avatar) {
      this.baseUrl = process.env.VUE_APP_API_BASE_URL + this.avatar
    } else {
      this.baseUrl = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
    }
  },
  computed: {
    ...mapGetters([
      'nickname',
      'avatar'
    ])
  },
  methods: {
    handleToCenter () {
      // const type = this.$store.getters.userInfo.UserType
      // // 当前登录用户是管理员
      // if (type === '0') {
      //   this.$router.push({ path: '/dashboard/WorkplaceOne' })
      // } else {
      //   this.$router.push({ path: '/dashboard/workplace' })
      // }
      console.log('2222222222222222222222222',store.state.user.roled.length,store.state.user.roled);
      if (store.state.user.roled.length === 0) {
        console.log('111111111111111111111111');
        this.$router.push({ path: '/reception/findServices/index' })
      }else {
        this.$router.push({ path: '/dashboard' })
      }
    },
    handleToSettings () {
      this.$router.push({ path: '/account/settings' })
    },
    handleLogout (e) {
      Modal.confirm({
        title: '提示',
        content: '真的要注销登录吗?',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          return this.$store.dispatch('Logout').then(() => {
            this.$router.push({ name: 'resLogin' })
          })
        },
        onCancel () {}
      })
    }
  }
}
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  /deep/ .action {
    margin-right: 8px;
  }
  /deep/ .ant-dropdown-menu-item {
    min-width: 160px;
  }
}
</style>
